#!/bin/bash
luajit=/d/engine/cocos/Cocos2d-x/cocos2d-x-3.10/tools/cocos2d-console/plugins/plugin_luacompile/bin/luajit.exe

# 第一种方式
find ../src-raw ! -name ".vscode" -type d | while read dir; do echo "make directory $dir"; mkdir -p ${dir/src-raw/src}; done
find ../src-raw -name "*.lua" | while read file; do echo "compile $file";  `$luajit -b $file ${file/src-raw/src}`; done
read -p "输入回车键结束..."
exit 0

# 第二种方式
#function makedir()
#{
#	for dir in $*
#	do
#		echo "make directory $dir"
#		mkdir -p ${dir/src-raw/src}
#	done
#}
#function compile()
#{
#	for file in $*
#	do
#		echo "compile $file"
#		`$luajit -b $file ${file/src-raw/src}`
#	done
#}
#makedir `find ../src-raw ! -name ".vscode" -type d`
#compile `find ../src-raw -name "*.lua"`
#read -p "输入回车键结束..."
#exit 0

# 第三种方式
#cd ..
#
#if [ ! -d src-raw ]; then
#	echo "src-raw 目录不存在！"
#	read -p "输入回车键结束..."
#	exit 1
#fi
#if [ ! -d src ]; then
#	mkdir src
#fi
#
#function compile()
#{
#	for sub in $1/*
#	do
#		if [ -f $sub ]; then
#			if [[ ${sub##*.} = lua ]]; then
#				dest=${sub/src-raw/src}
#				if [[ ! -f $dest ]] || [[ $sub -nt $dest ]]; then
#					echo compile $sub
#					`$luajit -b $sub $dest`
#				fi
#			fi
#		elif [ -d $sub ]; then
#			dest=${sub/src-raw/src}
#			if [ ! -d $dest ]; then
#				mkdir $dest
#			fi
#			compile $sub 
#		fi
#	done
#}
#
#compile ./src-raw
#read -p "输入回车键结束..."
#exit 0
